package 位运算;

public class 消失的两个数字10 {
    //https://leetcode.cn/problems/missing-two-lcci/description/
    public int[] missingTwo(int[] nums) {
        int tmp = 0;
        for (int i = 1; i <= nums.length + 2; i++)
            tmp ^= i;
        for (int x : nums)
            tmp ^= x;
        tmp &= -tmp;
        int[] ret = new int[2];
        for (int i = 1; i <= nums.length + 2; i++) {
            if((tmp & i) == 0) ret[0] ^= i;
            else ret[1] ^= i;
        }
        for (int x : nums) {
            if((tmp & x) == 0) ret[0] ^= x;
            else ret[1] ^= x;
        }
        return ret;
    }
}
